{extend name="app/admin/view/base.html"/}
{block name="resources"}
<style>
    .layui-card-body{
        display: flex;
        justify-content: space-around;
    }
    .layui-card-body .money{
        font-size: 20px;
        color: #000;
        font-weight: bold;
        margin-top: 10px;
        text-align: center;
        max-width: 250px;
    }
    .layui-card-body .subhead{
        font-size: 12px;
        margin-left: 3px;
        cursor: pointer;
    }
    .layui-table-box {
        overflow: inherit;
    }
    .layui-table-header {
        overflow: inherit;
    }
    .layui-table-header .layui-table-cell{overflow: inherit;}
    .ns-prompt .iconfont{font-size: 16px;color: rgba(0,0,0,0.7);cursor: pointer;font-weight: 500;margin-left: 3px;}
    .ns-prompt-con{font-weight: 500;text-align: left}
    .img_block_sty{width:40px;height:40px;}
    .img_sty{width:100%;height:100%;}
</style>

{/block}
{block name='main'}
<!-- 筛选面板 -->
<div class="layui-collapse ns-tips">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">操作提示</h2>
        <ul class="layui-colla-content layui-show">
            <li>酒店房间列表，可在此展示所有酒店房间</li>
        </ul>
    </div>
</div>

<div class="ns-screen layui-collapse" lay-filter="selection_panel">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">筛选</h2>
        <form class="layui-colla-content layui-form layui-show">
            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">房间名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="room_name" placeholder="请输入房间名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">房间状态：</label>
                    <div class="layui-input-inline">
                        <select name="status">
                            <option value="">全部</option>
                            <option value="1">上架</option>
                            <option value="2">下架</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">酒店：</label>
                    <div class="layui-input-inline">
                        <select name="hotel_id">
                            <option value="">全部</option>
                            {foreach $hotel_list as $hotel_list_k => $hotel_list_v}
                            <option value="{$hotel_list_v.hotel_id}">{$hotel_list_v.hotel_name}</option>
                            {/foreach}
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">添加时间：</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="start_time" readonly id="start_time" autocomplete="off" placeholder="开始时间" >
                        <i class="ns-calendar"></i>
                    </div>
                    <div class="layui-form-mid">-</div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="end_time" readonly id="end_time" autocomplete="off" placeholder="结束时间" >
                        <i class="ns-calendar"></i>
                    </div>
                </div>
            </div>

            <div class="ns-form-row">
                <button class="layui-btn ns-bg-color" lay-submit lay-filter="search">筛选</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
</div>



<table id="account_list" lay-filter="account_list"></table>


{/block}
{block name="script"}
<script type="text/html" id="action">
    <div class="ns-table-btn">
<!--        <a class="layui-btn" lay-event="edit">编辑</a>-->
        {{#  if(d.status == 1){  }}
        <a class="layui-btn" lay-event="removed">下架</a>
        {{#  }  }}
        {{#  if(d.status == 0){  }}
        <a class="layui-btn" lay-event="listed">上架</a>
        {{#  }  }}

    </div>
</script>

<script type="text/html" id="website_info">
    <div class="ns-table-tuwen-box">
        <div class="ns-img-box img_block_sty">
            {{#  if(d.hotel_img){  }}
            <img layer-src src="{{ns.img(d.hotel_img.split(',')[0])}}" class="img_sty"/>
            {{#  }else{  }}
            <img layer-src src="{:img($default_img.default_city_img)}" class="img_sty"/>
            {{#  }  }}
        </div>
        <div class="ns-font-box">
            <a href="javascript:;" class="ns-multi-line-hiding ns-text-color" title="{{d.hotel_name}}">{{d.hotel_name}}</a>
        </div>
    </div>
</script>


<script type="text/html" id="adv_image">
    <div class="ns-img-box">
        <div class="ns-img-box img_block_sty">
            {{#  if(d.images){  }}
            <img layer-src src="{{ns.img(d.images.split(',')[0])}}" class="img_sty"/>
            {{#  }else{  }}
            <img layer-src src="{:img($default_img.default_city_img)}" class="img_sty"/>
            {{#  }  }}
        </div>
    </div>
</script>
<script>
    function clickAdd()
    {
        location.href = ns.url('hotel://admin/hotel/add');
    }

    var start_time,end_time;
    layui.use(['laydate','form', 'laytpl'], function () {
        var laydate = layui.laydate,
            laytpl = layui.laytpl,
            form = layui.form,
            repeat_flag = false;

        form.render();

        //开始时间
        laydate.render({
            elem: '#start_time', //指定元素
            type: 'datetime'
            /* done: function(value, date, endDate){
                start_time = ns.date_to_time(value);
            } */
        });
        //结束时间
        laydate.render({
            elem: '#end_time', //指定元素
            type: 'datetime'
            /* done: function(value, date, endDate){
                end_time = ns.date_to_time(value);
            } */
        });

        /**
         * 搜索功能
         */
        form.on('submit(search)', function (data) {
            // data.field.start_time = start_time;
            // data.field.end_time = end_time;
            table.reload({
                page: {
                    curr: 1
                },
                where: data.field
            });
            return false;
        });

        var table = new Table({
            elem: '#account_list',
            url: ns.url("hotel://admin/room/lists"),
            cols: [
                [{
                    title: '房间图片',
                    unresize: 'false',
                    templet: '#adv_image',
                    width: '15%'
                },  {
                    field: 'room_name',
                    title: '房间名称',
                    unresize: 'false',
                    width: '15%'
                },{
                    field: 'price',
                    title: '价格',
                    unresize: 'false',
                    width: '8%'
                },{
                    title: '状态',
                    unresize: 'false',
                    width: '5%',
                    templet: function (data) {
                        return data.status == 1 ? '上架' : '下架';
                    }
                }, {
                    field: 'sort',
                    title: '排序',
                    unresize: 'false',
                    width: '8%'
                },{

                    title: '所属酒店',
                    unresize: 'false',
                    width: '20%',
                    templet: function (d) {
                        return d.hotel_name + ( d.direct==1?'(自营)':'(非自营)');
                    }
                },  {
                    title: '创建时间',
                    unresize: 'false',
                    width: '12%',
                    templet: function (res) {
                        if (res.create_time == 0) {
                            return '--';
                        } else {
                            return ns.time_to_date(res.create_time)
                        }
                    }
                }, {
                    title: '操作',
                    toolbar: '#action',
                    unresize: 'false',
                    width: '15%'
                }]
            ]
        });

        /**
         * 监听工具栏操作
         */
        table.tool(function (obj) {
            var data = obj.data;
            switch (obj.event) {
                /*case 'detail': //详情
                    location.href = ns.url("city://admin/website/detail", {"website_id": data.site_id});
                    break;*/
                case 'edit': //编辑
                    location.href = ns.url("hotel://admin/room/edit", {"room_id": data.room_id});
                    break;

                case 'delete'://删除

                    layer.confirm('确定要删除该房间吗?', function () {
                        if (repeat_flag) return;
                        repeat_flag = true;

                        $.ajax({
                            url: ns.url("hotel://admin/room/delete"),
                            data: {room_id: data.room_id},
                            dataType: 'JSON',
                            type: 'POST',
                            success: function (res) {
                                layer.msg(res.message);
                                repeat_flag = false;

                                if (res.code == 0) {
                                    table.reload();
                                }
                            }
                        });
                    });
                    break;

                case 'removed': //下架
                    removedRoom(data.room_id);
                    break;
                case 'listed': //上架
                    listedRoom(data.room_id);
                    break;
            }

        });


        //下架
        function removedRoom(room_id) {
            $.ajax({
                url: ns.url("hotel://admin/room/operationRoom"),
                data: {'room_id': room_id,'status':0},
                dataType: 'JSON',
                type: 'POST',
                success: function(res) {
                    layer.msg(res.message);

                    if (res.code == 0) {
                        table.reload();
                    }
                }
            });
        }

        //上架
        function listedRoom(room_id) {
            $.ajax({
                url: ns.url("hotel://admin/room/operationRoom"),
                data: {'room_id': room_id,'status':1},
                dataType: 'JSON',
                type: 'POST',
                success: function(res) {
                    layer.msg(res.message);

                    if (res.code == 0) {
                        table.reload();
                    }
                }
            });
        }
    })
</script>

{/block}